
#ifndef _TASK_H
#define _TASK_H
#include "config.h"
#include "memory/paging/paging.h"
#include "idt/idt.h"

struct registers
{
    uint32_t edi;
    uint32_t esi; 
    uint32_t ebp; 
    uint32_t ebx; 
    uint32_t edx; 
    uint32_t ecx; 
    uint32_t eax; 

    uint32_t ip; // program counter
    uint32_t cs; 
    uint32_t flags;
    uint32_t esp; 
    uint32_t ss; 
}
__attribute__((packed)); 

struct process; 
struct task 
{
    struct paging_4Gbyte_chunk* page_directory; 

    /*
     *  The registers of the task when the task is not running
     */
    struct registers registers; 

    struct task* next;

    struct task* prev;

    struct process* process; 
}
__attribute__((packed)); 

struct task* task_new(struct process* process); 
struct task* get_current_task(); 
struct task* task_get_next(); 
const int task_free(struct task* task);

void task_run_first_ever_task(); 
void task_return(struct registers* regs); 
void restore_general_purpose_registers(struct registers* regs); 
void user_registers();
void task_current_save_state(struct interrupt_frame* frame); 
const int copy_string_from_task(struct task* task, void* virt, void* phys, const int max);
void* task_get_stack_item(struct task* task, const int index); 

const int task_switch(struct task* task); 
const int task_page(); 

#endif 